﻿@model Epi.Web.MVC.Models.FormResponseInfoModel

 

<script>


    $(document).ready(function () {
        $("#btnsearch1").click(function () {
            $("#searchbox1").toggle();
        });

    });

    $(document).on("click", "button[name='Search1']", function (e) {

        e.preventDefault();
        $("#right").show();
        var formid = $("#LinkFormId_HIDDEN_0").val(); //$('#hidFormId').val();
        var pageNumber = $('#hidPageNumber').val();

        var Sort = $("#FORM_SORTORDER_HIDDEN").val();
        var SortField = $("#FORM_SORTFIELD_HIDDEN").val();
        ReadExistingLinkResponses(formid, 1, Sort, SortField, '@Model.FromResponseId');

    });


    $(document).on("click", "button[name='ResetSearch1']", function (e) {
        e.preventDefault();
        $("#right").show();
        var formid = $("#LinkFormId_HIDDEN_0").val();//$('#hidFormId').val();
        var pageNumber = $('#hidPageNumber').val();
        var Sort = ''; // $("#FORM_SORTORDER_HIDDEN").val();
        var SortField = ''; //$("#FORM_SORTFIELD_HIDDEN").val();
        var col1 = '';
        var val1 = '';
        var col2 = '';
        var val2 = '';
        var col3 = '';
        var val3 = '';
        var col4 = '';
        var val4 = '';
        var col5 = '';
        var val5 = '';

        $.ajax({
            url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=1&sort=" + Sort + "&sortfield=" + SortField + '&PartialViewName=' + "ListExistingResponse" + "&ResponseId=" + '@Model.FromResponseId'
            //   url: '@Url.Action("ReadSortedResponseInfo","Home")' + '?formid=' + formid + "&page=" + pagenumber + "&sort=" + sortOrder + "&sortfield=" + sortField + '&PartialViewName=' + "ListExistingResponse" + "&ResponseId=" + ResponseId
            + "&col1=" + col1 + "&val1=" + val1 + "&col2=" + col2 + "&val2=" + val2 + "&col3=" + col3 + "&val3=" + val3 + "&col4=" + col4 + "&val4=" + val4 + "&col5=" + col5 + "&val5=" + val5,
            cache: false,
            type: 'GET',
            contentType: 'application/json; charset=utf-8',
            //data: JSON.stringify(model),
            success: successFunc,
            error: errorFunc
        });
        //            $.ajaxSetup({ cache: false });

        function successFunc(data, status) {
            $('#LinkExistingdialog').html(data);
        }

        function errorFunc() {
            alert('error');
        }
    });
    $(document).on("click", "button[id='SortASC1']", function (e) {
        e.preventDefault();
        $("#right").show();
        var formid = $("#LinkFormId_HIDDEN_0").val();
        var pageNumber = $('#hidPageNumber').val();
        var Sort = 'ASC';
        var SortField = $("#columns1").val(); // 'PetsName';
        $("#FORM_SORTORDER_HIDDEN").val(Sort);
        $("#FORM_SORTFIELD_HIDDEN").val(SortField);
        ReadExistingLinkResponses(formid, 1, Sort, SortField, '@Model.FromResponseId');

    });

    $(document).on("click", "button[id='SortDESC1']", function (e) {
        e.preventDefault();
        $("#right").show();
        var formid = $("#LinkFormId_HIDDEN_0").val();
        var pageNumber = $('#hidPageNumber').val();
        var Sort = 'DESC';
        var SortField = $("#columns1").val(); // 'PetsName';
        $("#FORM_SORTORDER_HIDDEN").val(Sort);
        $("#FORM_SORTFIELD_HIDDEN").val(SortField);
        ReadExistingLinkResponses(formid, 1, Sort, SortField, '@Model.FromResponseId');

    });
</script>

<div id="RecordList">
    <div id="formtitle" class="formtitle">
        <h2 class="surveyTitle" style="line-height: 120%; display:none;">
            @Model.FormInfoModel.FormName
        </h2>
        <div id="NumberOfRecords" class="NumberOfRecords">
            <div>
                @{
                    if (Model.NumberOfPages == 0)
                    {
                        <span class="boldlabel">0 Records </span>
                    }
                    else
                    {

                        <span class="boldlabel">
                            @(
 Model.CurrentPage * Model.PageSize - (Model.PageSize - 1))
                            -
                            @if (Model.CurrentPage * Model.PageSize < Model.NumberOfResponses)
                            {
                                @(Model.CurrentPage * Model.PageSize)
                            }
                            else
                            {
                                @Model.NumberOfResponses
                            }
                        </span>
                        <span>of </span><span class="boldlabel">
                            @Model.NumberOfResponses
                        </span>
                    }
                }
            </div>
        </div>

    </div>
    <div id="editsettings" class="editsettings">


        @if (Model.FormInfoModel.IsSQLProject)
        {
            <span>&nbsp;&nbsp;</span>
            <button id="btnsearch1" onclick="" class="default search" type="button">Search</button>
        }

    </div>
    <div style="clear: both"></div>

    <div id="searchbox1" style="display: none;">
        <div class="searchrow">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol1Existing, Model.SearchColumns1, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value1Existing, string.Empty)
        </div>
        <div class="searchrow">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol2Existing, Model.SearchColumns2, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value2Existing, string.Empty)
        </div>
        <div class="searchrow">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol3Existing, Model.SearchColumns3, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value3Existing, string.Empty)
        </div>
        <div class="searchrow">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol4Existing, Model.SearchColumns4, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value4Existing, string.Empty)
        </div>
        <div class="searchrow" style="display: inline-block; margin-right: 8px;">
            @Html.DropDownListFor(m => m.SearchModel.SearchCol5Existing, Model.SearchColumns5, string.Empty)
            @Html.TextBoxFor(m => m.SearchModel.Value5Existing, string.Empty)
        </div>
        <button class="default" name="Search1">Go</button>
        <button class="default" name="ResetSearch1">Reset</button>
    </div>
    @{
        WebGrid webGrid = new WebGrid(rowsPerPage: 20,
            canSort: false, canPage: false, ajaxUpdateContainerId: "recordstable"); // Model.SurveyAnswerResponse.pageSize
        webGrid.Bind(Model.ResponsesList, autoSortAndPage: false, rowCount: Model.NumberOfResponses); //Model.SurveyAnswerResponse.pageSize * Model.ResponsesList.Count TBD
    }
    <div id="recordscontent" class="recordscontent">
        <div style="clear: both; margin-bottom: 10px; padding: 0px 0 0;">
            @if (Model.FormInfoModel.IsSQLProject && Model.SearchModel.SearchCol1Existing != null)
            {
                <div id="searchmsg" style="display:block; background:#ffdead; padding:5px 5px 9px; color:#794800; margin: 2px 0 15px 0;">
                    <span>
                        Only showing records matching your search criteria. &nbsp;&nbsp;&nbsp;
                        <button class="default" name="ResetSearch1" style="float:right;">Reset</button>
                    </span>
                </div>
            }

            <div style="position:relative; margin-top: 5px;">
                @if (Model.FormInfoModel.IsSQLProject)
                {
                    <div id="tableSort" class="tableSort" style="vertical-align: middle;">
                        <select id="columns1" style="width: 172px;">
                            @foreach (var item in Model.Columns)
                            {
                                if (@item.Value.ToString() == @Model.sortfield)
                                {
                                    <option value="@item.Value.ToString()" selected=selected>@item.Value.ToString()</option>
                                }
                                else
                                {
                                    <option value="@item.Value.ToString()">@item.Value.ToString()</option>
                                }
                            }
                        </select>
                        <button id="SortASC1" class="default" style="padding:0 8px; vertical-align: top; height:24px; ">
                            <img src="~/Content/images/Sort-Ascending.png" style="width: 13px; vertical-align: middle;" />
                        </button>
                        <button id="SortDESC1" class="default" style="padding:0 8px; vertical-align: top; height:24px;">
                            <img src="~/Content/images/Sort-Descending.png" style="width: 13px; vertical-align: middle;" />
                        </button>


                    </div>
                }
                
                    @{

                        if (Model.NumberOfPages > 1)
                        {
                            <div id="paging" class="paging" style="margin-top: 6px;">
                                <div id="pager" class="pager">
                                    @Html.Partial("ExistingResponsePagerPartial", Model)
                                </div>
                            </div>
                        }


                    }
                
                <div style="clear: both; margin-bottom: 15px;"></div>
            </div>

            <div id="Existingrecordstable" class="recordstable existcontactlist">
                @{
                    var gridColumns = new List<WebGridColumn>();


                    gridColumns.Add(webGrid.Column(header: "",
                        format: (item) => new HtmlString("<input type='radio' name='LinkCheckBox'  onclick='EnableButton();' class='default LinkCheckBox'  id='" + item.Column0 + "'value='" + item.Column0 + "'>")));
                    if (Model.Columns.Count >= 1)
                    {
                        gridColumns.Add(webGrid.Column("Column1", (Model.Columns.Count >= 1) ? Model.Columns[0].Value : ""));
                    }
                    if (Model.Columns.Count >= 2)
                    {
                        gridColumns.Add(webGrid.Column("Column2", (Model.Columns.Count >= 2) ? Model.Columns[1].Value : ""));
                    }
                    if (Model.Columns.Count >= 3)
                    {
                        gridColumns.Add(webGrid.Column("Column3", (Model.Columns.Count >= 3) ? Model.Columns[2].Value : ""));
                    }
                    if (Model.Columns.Count >= 4)
                    {
                        gridColumns.Add(webGrid.Column("Column4", (Model.Columns.Count >= 4) ? Model.Columns[3].Value : ""));
                    }
                    if (Model.Columns.Count >= 5)
                    {
                        gridColumns.Add(webGrid.Column("Column5", (Model.Columns.Count >= 5) ? Model.Columns[4].Value : ""));
                    }

                    @webGrid.GetHtml(columns: gridColumns);
                }
                @Html.Hidden("hidFormId", @Model.FormInfoModel.FormId)
                @Html.Hidden("hidPageNumber", @Model.CurrentPage)
                @{
                    if (Model.NumberOfPages == 0)
                    {
                        <div class="zerorec">
                            No records found.
                        </div>
                    }
                }

            </div>
            <div style="float:right; padding:5px 5px 10px;">

                @*<button id="AddLinks" onclick="AddLinks();" class="default" type="button" style="height:24px; vertical-align: top;">Link Contact</button>*@
                <button id="AddLinkInfo" onclick="AddLinkInfo();" class="default" disabled="disabled" type="button" style="height:24px; vertical-align: top;">Add Link Info</button>

            </div>

            <div style="clear: both;"></div>











        </div>
    </div>
</div>
<script>
    $('#contactdate').datepicker({ onClose: function () { setTimeout(datereport_after, 100); }, changeMonth: true, changeYear: true, yearRange: '-110:+10' });


</script>
<script>

    $('#contactdate').BlockEnter('contactdate');

</script>

<div id="LinkInfo" style="display:none;">

    @Html.Partial("LinkInfoPartial")
    <div style="margin-top:25px;">
        <button onclick="AddLinks()" class="default" type="button" style="height:24px; vertical-align: top;">
            Save
        </button>
        <button onclick="Cancel()" class="default" type="button" style="height:24px; vertical-align: top;">Cancel</button>
    </div>
</div>
    @*  <script type="text/javascript">
        var formId =  document.getElementById('hidFormId').value; //$('#hidFormId').val();
        var pageId = $('#hidPageNumber').val();
            var returnUrl = 'returnUrl=' + formId + '/' + pageId;
            var redirectTimeout = @FormsAuthentication.Timeout.TotalMilliseconds
            var redirectTimeoutHandle = setTimeout(function() { window.location.href = '@FormsAuthentication.LoginUrl' + '?'+ returnUrl; }, redirectTimeout);
        </script>*@
